<?php


namespace app\voip\func;


use app\voip\model\EExcelAuth;
use app\voip\model\EExcelAuthAccess;
use think\Db;

class ExcelAuthFunc
{
    /**
     * @param $where
     * @param $rows
     * @param $param
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    static public function list($where,$rows,$param)
    {
        $obj=new EExcelAuth();
        return $obj->where($where)->order('id desc')->paginate($rows,false,['query'=>$param]);
    }

    /**
     * @param $where
     * @param $rows
     * @param $param
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    static public function userList($where, $rows, $param)
    {
        return Db::name('e_excel_auth_access')->alias('e1')->join('e_excel_auth e2','e1.gid=e2.id')
            ->join('admin a1','e1.uid=a1.id')
            ->order('e1.id desc')->where($where)->field('e1.*,e2.title,a1.username')->paginate($rows,false,['query'=>$param]);
    }

    /**
     * @param $id
     * @return EExcelAuth|null
     * @throws \think\exception\DbException
     */
    static public function getInfo($id)
    {
        return EExcelAuth::get(['id'=>$id]);
    }

    /**
     * @param $id
     * @return EExcelAuthAccess|null
     * @throws \think\exception\DbException
     */
    static public function userGetInfo($id)
    {
        return EExcelAuthAccess::get(['id'=>$id]);
    }

    /**
     * @param $data
     * @return false|int
     */
    static public function edit($data)
    {
        $obj=new EExcelAuth();
        return $obj->allowField(true)->isUpdate()->save($data);
    }
    /**
     * @param $data
     * @return false|int
     */
    static public function userEdit($data)
    {
        $obj=new EExcelAuthAccess();
        return $obj->allowField(true)->isUpdate()->save($data);
    }
    /**
     * @param $data
     * @return false|int
     */
    static public function add($data)
    {
        $obj=new EExcelAuth($data);
        return $obj->allowField(true)->save();
    }

    /**
     * @param $data
     * @return false|int
     */
    static public function userAdd($data)
    {
        $obj=new EExcelAuthAccess();
        return $obj->allowField(true)->save($data);
    }


    /**
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static public function userFindGid($where)
    {
        $obj=new EExcelAuthAccess();
        return $obj->where($where)->select();
    }

    static public function userFindAuthEid($where)
    {
        $obj=new EExcelAuth();
        return $obj->where($where)->select();
    }
}